package time;

import java.time.Clock;
import java.time.ZoneId;
import java.time.ZonedDateTime;

/**
 * 时区相关测试
 */
public class ZoneTest {
    public static void main(String[] args) {
//        zoneIds();
        zoneTime();
    }

    private static void zoneTime() {
        // 世界标准时间
        ZonedDateTime standardTime = ZonedDateTime.now(Clock.systemUTC());
        // 计算机默认时区时间
        ZonedDateTime localTime = ZonedDateTime.now();
        // 指定时区时间
        ZonedDateTime customTime = ZonedDateTime.now(ZoneId.of("America/Grenada"));
        // 更改时区时间
        ZonedDateTime zoneTime = customTime.withZoneSameInstant(ZoneId.of("Asia/Shanghai"));
        // 只改时区，不改时间
        ZonedDateTime zone = customTime.withZoneSameLocal(ZoneId.of("Asia/Shanghai"));
        System.out.println("standardTime = " + standardTime);
        System.out.println("localTime = " + localTime);
        System.out.println("customTime = " + customTime);
        System.out.println("zoneTime = " + zoneTime);
        System.out.println("zone = " + zone);
    }

    private static void zoneIds() {
        ZoneId.getAvailableZoneIds().forEach(System.out::println);
    }
}
